
<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://shiro.apache.org/tags" prefix="shiro" %>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>收支记录</title>
<link rel="stylesheet" type="text/css" href="../easyui/themes/bootstrap/easyui.css">
<link rel="stylesheet" type="text/css" href="../easyui/themes/icon.css">
<link rel="stylesheet" type="text/css" href="../plugins/font-awesome/css/font-awesome.min.css">
	<script type="text/javascript" src="../myjs/path.js"></script>
<style type="text/css">
	.list{
		list-style: none;
	}
	.list li{
		margin-top: 10px;
	}
	.list li:hover{
		background-color: #ccc
	}
	.list a{
		text-decoration: none;
		color: black;
	}
	
	#w{
		display: none;
	}
	.w{
		border: 1px solid #ccc;
		width: 350px;
		border-collapse: collapse;
		margin:auto;
		
	}
	.w td{
		border: 1px solid #ccc;
		padding: 10px;
	}
	
	.w tr td:nth-child(odd){
		background-color: #eee;
	}
	
</style>
<script type="text/javascript" src="../easyui/jquery.min.js"></script>
<script type="text/javascript" src="../easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../easyui/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="../js/dateFormat.js"></script>
<script type="text/javascript" src="../myjs/path.js"></script>
<script src="../js/yangshi.js"></script>
</head>
<body>
<shiro:lacksPermission name="finance:szjl:look">没有查询此模块权限。。。</shiro:lacksPermission>
<shiro:hasPermission name="finance:szjl:look">
	<div id="cc" class="easyui-layout" data-options="fit:true">
		<table id="tbl"></table>
	</div>
	<!-- toolbar -->
	<div id="tb">

			<select class="easyui-combobox" name="hl" id="HL" style="width: 60px;" data-options="editable:false">
				<option value="">全部</option>
				<option value="-1">红单</option>
				<option value="1">蓝单</option>
			</select>
			<input class="easyui-textbox"  id="LSH">
			<a class="easyui-linkbutton" onclick="search1()" data-options="iconCls:'icon-search'" style="width:80px">搜索</a>

			<shiro:hasPermission name="finance:szjl:create">
			<a onclick="showReocrdBox()" class="easyui-linkbutton" data-options="iconCls:'icon-add'">记录收付款</a>
			</shiro:hasPermission>

	</div>

	<!-- 记账对话框 -->
	<div id="w" class="easyui-window" title="<i class='fa fa-pencil-square-o' aria-hidden='true'></i> 记账"
		data-options="modal:true,closed:true" style="width: 400px; height: 520px; padding: 5px;">
		<form id="record">
			<input type="hidden" value="1" name="q">
			<table class="w">
				<tr>
					<td>红蓝单</td>
					<td>
						<label> <input type="radio" name="hl" value="1" checked="checked" class="mr"> 蓝单 </label>
						<label> <input type="radio" name="hl" value="-1"> 红单 </label>
					</td>
				</tr>
				<tr>
					<td>原订单号</td>
					<td><input style="width: 200px;" name="ldid" id="ldid"></td>
				</tr>

				<tr>
					<td>所属年季</td>
					<td>
						<label>  <input style="width: 200px;" name="yearandseason" id="yearandseason" class="easyui-combobox"data-options="valueField:'id',textField:'text',required:true"></label>
					</td>
				</tr>


				<tr>
					<td>单位类型</td>
					<td>
						<label>  <input type="radio" name="wldwtype" value="0" checked="checked" class="mr"> 机构 </label>
						<label>  <input type="radio" name="wldwtype" value="1"> 批发客户 </label>
					<%--	<label>  <input type="radio" name="wldwtype" value="2"> 零售客户 </label>--%>
					</td>
				</tr>
				<tr>
					<td>往来单位</td>
					<td>
						<input style="width: 200px;" name="wldwid" id="wldw">
					</td>
				</tr>
				<tr>
					<td>支付方式</td>
					<td>
						<label> <input type="radio" name="payType" value="0" checked="checked" class="mr"> 银行转账 </label>
						<label> <input type="radio" name="payType" value="1"> 现金 </label>
						<label> <input type="radio" name="payType" value="2"> 支付宝 </label>
						<label> <input type="radio" name="payType" value="3"> 微信 </label>
					</td>
				</tr>
				<tr>
					<td>支付金额</td>
					<td><input class="easyui-numberbox" style="width: 200px;" name="money" data-options="required:true,min:1,precision:2"></td>
				</tr>

				<tr>
					<td>优惠金额</td>
					<td>
						<label> <input class="easyui-numberbox" style="width: 200px;" name="yh_money" data-options="min:1,precision:2" ></label>

					</td>
				</tr>
				<tr>
					<td>备注</td>
					<td><input class="easyui-textbox"
						data-options="multiline:true" style="height: 60px; width: 200px;"
						name="remark"></td>
				</tr>
				<tr>
					<td colspan="2" style="background-color: #fff; text-align: right;">
						<a class="easyui-linkbutton" onclick="postItem()" id="save"><i class="fa fa-pencil-square-o" aria-hidden="true" ></i> 保 存</a>
						<a class="easyui-linkbutton" onclick="postCancle()"><i class="fa fa-reply" aria-hidden="true"></i> 取 消</a>
					</td>
				</tr>

			</table>
		</form>
	</div>
	<input id='jgid' type="hidden"  value="<%=request.getParameter("jgid")%>">
	<input id='parentId' type="hidden"  value="<%=request.getParameter("parentId")%>">
	<input id='jgleixing' type="hidden"  value="<%=request.getParameter("jgleixing")%>">
	</shiro:hasPermission>
</body>
<script type="text/javascript">
    //生成
	$(function(){
	    A()
	})
    function A() {
        var year = "" + new Date().getFullYear();
        var yearandseason = [{
            "id": (parseInt(year) + 1) + "春夏",
            "text": (parseInt(year) + 1) + "春夏"
        }, {
            "id": (parseInt(year) + 1) + "秋",
            "text": (parseInt(year) + 1) + "秋"
        }, {
            "id": (parseInt(year) + 1) + "冬",
            "text": (parseInt(year) + 1) + "冬"

        }, {
            "id": year + "春夏",
            "text": year + "春夏"
        }, {
            "id": year + "秋",
            "text": year + "秋"
        }, {
            "id":  year + "冬",
            "text": year + "冬",

        }]
        $("#yearandseason").combobox("loadData", yearandseason)

    }
	/*
	 *
	 * 先查出所有的机构和客户
	 */
    var wldwArray=[];
//获得所有客户
 /*   $.ajax({
        url:path+"/finance/findallkehu.do",
        dataType:'json',
        success:function(data){
            if(data.code==200){
                wldwArray[0]=data.data;
            }else{
                alert("客户加载失败!")
            }
        }
    })*/
   function getList() {

       $("#tbl").datagrid({
           url: path + '/finance/transactionRecord.do',
           queryParams: {
               hl:$("#HL").combobox('getValue'),
               lsh:$("#LSH").val(),
               gsjg:''

           },})

}
    function search1(){
        getList()
    }

    $(document).keyup(function (event) {
        if (event.keyCode == 13) {
            getList()
        }
    });
$(function(){
    getList()
	// 加载表单
	$("#tbl").datagrid({
		toolbar : '#tb',
		fit : true,
		striped : true,
		fitColumns : false,
		singleSelect : true,
		rownumbers : true,
		nowrap : false,
		pagination : true,
		pageSize : 50,
		pageList : [ 10, 20, 50, 100 ],
		showFooter : true,
		loadMsg : '玩命加载中......',
		columns : [ [ 
		{
			field : 'id',
			title : '编号（需要隐藏）',
			width : 50,
			align : 'right',
			hidden: true
		}, {
                field: 'ldid',
                title: '订单编号',
                width: 150,
                align: 'center'
            },
		{
			field : 'wldwName',
			title : '往来单位',
			width : 150,
			align : 'center'/*,
			formatter:function(value,data){
				return formatJG(value,data);
			}*/
		}, 
		{
			field : 'hl',
			title : '红蓝标记',
			width : 100,
			align : 'center',
			formatter:function(value,data){
				if(value==1)
					return "蓝";
				else
					return "红";
			}
		}, 
		{
			field : 'money',
			title : '支付金额',
			width : 100,
			align : 'right',
			formatter:function(value){
				if(value==0)
					return value;
				return value.toFixed(2);
			}
		},
            {
                field : 'yh_money',
                title : '优惠金额',
                width : 100,
                align : 'right',
                formatter:function(value){
                    if(value!=null){
                        if(value==0)
                            return value;
                        return value.toFixed(2);
					}else{
                        return value
					}

                }
            },
            {
                field : 'yearandseason',
                title : '所属年季',
                width : 150,
                align : 'center'
            },
		{
			field : 'payType',
			title : '支付方式',
			width : 100,
			align : 'center',
			formatter:function(value){
				var t = "其他";
				if(value==0)
					t="银行转账";
				else if(value==1)
					t="现金";
				else if(value==2)
                    t="支付宝";
                else if(value==3)
                    t="微信";
				return t;
			}
		}, 
		{
			field : 'type',
			title : '交易类型',
			width : 100,
			align : 'center',
			formatter:function(value){
				return value;
			}
		},  
		{
			field : 'pjh',
			title : '票据号',
			width : 100,
			align : 'right',
			formatter:function(value){
				return value;
			}
		}, 
		{
			field : 'jbr',
			title : '经办人',
			width : 100,
			align : 'center',
			formatter:function(value){
				return value;
			}
		},
		{
			field : 'sp',
			title : '实付平账',
			width : 80,
			align : 'center',
			formatter:function(value){
				return 'ok';
			}
		}, 
		{
			field : 'statue',
			title : '状态',
			width : 50,
			align : 'center',
			formatter:function(value){
				return value;
			}
		}, 
		{
			field : 'tranTime',
			title : '时间',
			width : 160,
			align : 'center',
			formatter:function(value){
				return new Date(value).Format("yyyy/MM/dd hh:mm:ss");
			}
		}, 
		{
			field : 'remark',
			title : '备注',
			width : 200,
			align : 'center'
		}
		] ],
        onLoadSuccess: function (node, data) {

        }
	})
	// tbl end
	
	$("[name=ldid]").combobox({ disabled: true ,required:true});
})


function showReocrdBox(){
	$("#w").window('open')
}

$("[name=wldwtype]").change(function(){
	if($(this).val()==0){
        $("#wldw").combobox('clear')
        wldwTypeChange2()
	}else if($(this).val()==1){
		wldwTypeChange1()
	}else if($(this).val()==2){
        wldwTypeChange3()
    }
})

$("[name=hl]").change(function(){
	if($(this).val()==1){
		$("#ldid").combobox({ disabled: true });
	}else if($(this).val()==-1){
		$("#ldid").combobox({ disabled: false});
        $("#ldid").combobox({
            method: 'GET',
            url: path+'/finance/selectByJgid.do',
            disabled: false,
            required: true,
            valueField: 'ldid',
            textField: 'ldid'
        })
	}
})

function wldwTypeChange1(){
	$("#wldw").combobox({
        url: path + '/pifashang/jglist.do',
        required: true,
        valueField : 'id',
        textField : 'kehuming',
        loadFilter: function (data) {
            console.log(data)
            return data.data
		}
	})
}

function wldwTypeChange2(){
    $('#wldw').combobox({
        url: path + '/jg/selectjgforleixing.do',
        valueField: 'id',
        textField: 'kehuming',
        loadFilter: function (data) {
            return data.data

        }
    });

}

    /*function wldwTypeChange3(){
        $('#wldw').combobox({
            url: path + '/jg/selectjgforleixing.do',
            valueField: 'id',
            textField: 'kehuming',
            loadFilter: function (data) {
                return data.data

            }
        });

    }*/

setTimeout(wldwTypeChange2,2000)

function postItem(){
		if(!$('#w').form('validate')){
            return;
		}
    $('#save').linkbutton('disable');
		$.ajax({
			url: path+'/finance/transaction.do',
			method : 'POST',
			dataType:'json',
			data:$("#record").serialize(),
			success:function(data){
				if(data.code==0){
                    postCancle()
                    $('#save').linkbutton('enable');
                    getList()
                    $.messager.show({
                        title:'提示',
                        msg:'添加成功！',
                        timeout:1000,
                        showType:'slide'
                    });
				}
				else{
					alert("网络异常，请刷新页面重试!")
                    $('#save').linkbutton('enable');
				}
			}
			,error:function(){
				alert("呀！出意外了……")
                $('#save').linkbutton('enable');
			}
		})
	}

	function postCancle(){
      $("#record").form("clear");
		$('#w').window('close')
        $('.mr').prop("checked", true);
        $("#ldid").combobox({ disabled: true });
        wldwTypeChange2();
	}

	function formatJG(value,data){
		var t = data.wldwtype;
		if(t==0){
			for(var i=0;i<wldwArray[t].length;i++){
				if(value==wldwArray[t][i].id){
					return wldwArray[t][i].wldwName
				}
			}
		}
		return "其他单位";
	}




//格式化时间
Date.prototype.Format = function (fmt) { //author: meizz 
    var o = {
        "M+": this.getMonth() + 1, //月份 
        "d+": this.getDate(), //日 
        "h+": this.getHours(), //小时 
        "m+": this.getMinutes(), //分 
        "s+": this.getSeconds(), //秒 
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
        "S": this.getMilliseconds() //毫秒 
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}
</script>
</html>